home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Precision Software Appli…tions Silver Collection 4
/
Precision Software Applications Silver Collection Volume 4 (1993).iso
/
stats
/
chadyn.exe
/
YBIFM.C
< prev
next >
Wrap
C/C++ Source or Header
|
1988-11-28
|
12KB
|
418 lines
/********************************* YBIFM.C ***********************************/
/********************* (C) 1986,7,8 by JAMES A. YORKE ************************/
#include "yinclud.h"
#define PRINTWIDTH 260
#define WIDTH 700
#define BIF_PRE_ITERATES 200
#define BIF_ITERATES 700
#define BIF_LINES 400
static int borderFlag = YES;/* cannot be changed; this determines if a
border is drawn */
static int Contin,
threshhold = CORECOLS;
static int border = PRINTWIDTH;
static char bifP[CORECOLS]; /* 960 */
static double firstrho = -9999.,
lastrho = -9999.;
static long m,
printerLines,
bifLines = BIF_LINES;
long bifPreIterates = BIF_PRE_ITERATES,
bifIterates = BIF_ITERATES;
static int bifFlag = ON;
bif()
{
double oldrho = rho; /* save current value */
char maskChar;
int i,
j,
n,
prt,
cs;
long ii,
k;
double drho,
dx,
h;
FILE *prn;
unsigned counter,
totalCount[8];
int didprint = NO;
int level1;
level1 = ++level;
printerLines = bifLines / 8;
Contin = YES;
counter = 0;
if(firstrho == -9999.|| lastrho == -9999.) {
PRINT
" You must first give beginning and ending values for rho \n");
PRINT "Use command BIFS(BIFurcation Scale) \n");
return;
}
if(firstrho == lastrho) {
PRINT
"The beginning and last rho CANNOT be equal; set using BIFS \n");
return;
}
if(X_coord < 0) {
PRINT
"The X_coord number(now = %d) cannot be < 0 ; reset using command COORDS \n"
,X_coord);
return;
}
prn = stdprn;
if(bifFlag == OFF)
border = 0; /* parameter will not be printed out */
i12print(); /* tells printer to use regular spacing(for
text) */
printf(
"*********************************************************************\n");
printf(
"* This routine is for creating bifurcation diagrams, i.e. *\n");
printf(
"* the X coordinate of the process is plotted horizontally on paper *\n");
printf(
"* using an Epson printer or compatible *\n");
printf(
"* and the parameter rho is varied vertically *\n");
printf(
"*********************************************************************\n");
printf(" \n");
printf(" \n");
bifTextFlag = ON;
print_text(stdout); /* prints text header at top of picture */
print_text(prn); /* prints text header at top of picture */
bifTextFlag = OFF;
if(bifLines != 1)
printf("rho runs from %13.13lf to %13.13lf in steps of %13.13lf \n",
firstrho, lastrho, (lastrho - firstrho) / (bifLines - 1));
printf("plotting X = y[%d] \n", X_coord);
printf("%ld preiterates; %ld bifIterates; %ld values of rho\n\n"
,bifPreIterates, bifIterates, bifLines);
if(bifLines > 1)
fprintf(prn,
"rho runs from %15.13lf to %15.13lf in steps of %13.13lf;\n",
firstrho, lastrho, (lastrho - firstrho) / (bifLines - 1));
fprintf(prn, "plotting X = y[%d] \n", X_coord);
fprintf(prn, "%ld preiterates; %ld iterates; %ld values of rho\n\n\n\n",
bifPreIterates, bifIterates, bifLines);
drho = (lastrho - firstrho) / (8 * printerLines - 1);
/* drho is the change in rho; the number of
steps is printerLines*8 -1; */
dx = WIDTH / (X_upper - X_lower);
h = -dx * X_lower;
iprint(printerSpacing);/* in YPRINTER.C, initializes printer spacing
for graphics */
for(m = 0; m < printerLines && Contin == YES && level >= level1
; m = m + 1) {
for(i = 0; i < printerWidth; i++)
bifP[i] = 0;
if(borderFlag == YES)
bifP[border] = bifP[printerWidth - 1] = 255;
/* all bits = 1 */
rho = 8.* drho * m + firstrho;
#ifdef MS
fflush(stdprn);
#endif
for(n = 0; n <= 7 && Contin == YES && level >= level1
; n = n + 1) {
#ifndef MAINFRAME
if(ChkKeyStatus() != 0 || cycle > 0)
Interrupt();
#endif
j = 8 * m + n;
rho = drho * j + firstrho;
maskChar = mask[n];
if(InitFlag == ON)
store(y, y + eqnsL, dim);/* initialize y */
for(k = 1; k <= bifPreIterates; k = k + 1) {
(*iteratee) ();
}
if(threshhold < printerWidth) {
counter = 0;
for(k = 1; k <= bifIterates; k++) {
(*iteratee) ();
i = ii = dx * y[X_coord] + h + border;
/* effective WIDTH is printerWidth -border,
which may not be printerWidth; integer part
should be a long */
if(ii >= border
&& ii < printerWidth) {
if((bifP[i] & maskChar) == 0) {
bifP[i] = bifP[i] | maskChar;
counter++;
}
}
}
totalCount[n] = counter;
} /* end if threshhold < printerWidth */
if(threshhold >= printerWidth) {
/* then ignore threshhold */
for(k = 1; k <= bifIterates; k++) {
(*iteratee) ();
/*if(printer == 1)
printf(": k=%ld,x=%lf \r",k,y[X_coord]);
*/
i = ii = dx * y[X_coord] + h + border;
/* effective WIDTH is printerWidth -border,
which may not be printerWidth; integer part
should be a long */
if(ii >= border
&& ii < printerWidth)
bifP[i] = bifP[i] | maskChar;
}
} /* end if threshhold >= printerWidth */
cs = keycheck();
if(cs == ESC || cs == ' ') {
/* is printing being interrupted? Note Esc = 27
*/
Contin = NO;
/* space bar stops printing and returns program
to parameter selection */
}
}
if(printer > 1 && threshhold < printerWidth)
printf(
"\rrho=%9.9lf count=%d,%d,%d,%d,%d,%d,%d,%d,thresh=%d__"
,rho, totalCount[0], totalCount[1], totalCount[2], totalCount[3]
,totalCount[4], totalCount[5], totalCount[6], totalCount[7], threshhold);
if(printer > 1 && threshhold >= printerWidth)
printf(
"\rrho=%9.9lf ", rho);
if(Contin == YES) {
if(threshhold >= printerWidth ||
(totalCount[0] <= threshhold ||
totalCount[1] <= threshhold ||
totalCount[2] <= threshhold ||
totalCount[3] <= threshhold ||
totalCount[4] <= threshhold ||
totalCount[5] <= threshhold ||
totalCount[6] <= threshhold ||
totalCount[7] <= threshhold)) {
if(bifFlag == ON)
for(prt = 1; prt == 1 || prt <= onprint; prt++)
fprintf(prn, "rho=%14.14lf\r", rho);
multi_strike();
didprint = YES;
}
else { /* we skip a line after each break in printing
*/
if(didprint == YES)
fprintf(prn, "skip\n");
didprint = NO;
}
} /* end if Contin */
}
i12print(); /* tells printer to return to regular spacing
*/
printf(" \n");
fprintf(prn, "\n\n\n\n\n");
rho = oldrho; /* restore original value */
#ifdef MS
fflush(stdprn);
#endif
level = level1 - 1;
}
multi_strike() { /* similar to vprint */
int i,
prt;
for(prt = 1; (prt == 1 || prt <= onprint) && Contin == YES; prt++) {
print_graphics_mode();
for(i = 0; i < printerWidth; i = i + 1) {
C = bifP[i];
#ifndef X11
printChar();
#endif
}
carriage_return();
}
line_feed(); /* line feed */
}
bifdisk(fff) /* for disk printing for DD and TD commands;
called in YDISK.C */
FILE * fff;
{
if(firstrho != -9999.|| lastrho != -9999.)
fprintf(fff,
"BIFS %15.15lf %15.15lf /* BIF parameter Scale */ \n", firstrho, lastrho);
if(bifFlag == OFF)
fprintf(fff,
"BIFP /* toggle turns off feature where BIF prints parameters with pic */ \n");
if(bifPreIterates != BIF_PRE_ITERATES || bifIterates != BIF_ITERATES)
fprintf(fff,
"BIF2 %ld %ld /* preiterates, iterates */\n"
,bifPreIterates, bifIterates);
if(bifLines != BIF_LINES)
fprintf(fff,
"BIFL %ld /* = the number of values of rho */\n"
,bifLines);
if(threshhold != CORECOLS)
fprintf(fff,
"BIFT %d /* threshhold value below which we print */\n"
,threshhold);
}
setdots(numRhos) /* for trajectory() in Y.C, for plotting
bifuracation diagrams on the screen; this is
here because the two bif... variables are
static and cannot be accessed from Y.C */
int numRhos;
{
dots = numRhos * (bifPreIterates + bifIterates);
}
int bifCommands(CodeName) /* called from YCOMNDS.C */
char *CodeName;
{
TEST("bif") { /* command to have the printer make a strip map */
bif(); /* in YBIFM.C */
return(1);
}
TEST("bifi") {
InitFlag = 1 - InitFlag;
if(SCREEN) {
PRINT "Flag for reinitializing y for each rho is now");
toggle(InitFlag);
}
return(1);
}
TEST("bifp") {
bifFlag = 1 - bifFlag;
if(SCREEN) {
PRINT
"Flag for printing parameter values continuously is now\n");
toggle(bifFlag);
}
return(1);
}
TEST("bifs") { /* parameter scale for bifurcation strip */
EnterScale(&firstrho, &lastrho);
return(1);
}
TEST("bif2") { /* sets preiterates and iterates */
bif2 (); /* in YBIFRCAT.C */
return(1);
}
TEST("bifl") { /* sets number if printer lines */
if(SCREEN)
printf(
"Enter the number of lines, i.e. the number of values of rho\n");
bifLines = (long) Entervalue((double) bifLines, CHECKSET);
printerLines = bifLines / 8;
return(1);
}
TEST("bift") { /* sets threshhold number for printing 8 lines
*/
threshhold = (int) Entervalue((double) threshhold, CHECKSET);
return(1);
}
return(0);
}
bifMenu() { /* call ed by command BIFM */
if(level == SETPARAM)
scr_clr(); /* in desmets pcio.a */
scr_rowcol(1, 0);
PRINT
" BIFURCATION MENU FOR MAKING BIFURCATION DIAGRAMS\n\n");
PRINT
" \n");
PRINT
" BIF2: set preiterates and iterates, now %ld,%ld\n"
,bifPreIterates, bifIterates);
PRINT
" BIFI: re-Initialize y[] for each rho, currently");
toggle(InitFlag);
PRINT
"\nThe following BIFx commands are ONLY for diagrams made on the PRINTER \n");
PRINT
" BIF: makes a BIFurcation diagram on the printer\n");
PRINT
" BIFL: set lines, (about 720 per page); now = %ld\n"
,bifLines);
PRINT
" BIFP: Print Parameter values as the strip is plotted, currently");
toggle(bifFlag);
PRINT
" BIFS: Scale, i.e., the range of parameter, now %lf to %lf\n"
,firstrho, lastrho);
PRINT
" BIFT: prints data only if 1 of 8 lines has <= Threshhold dots, now = %d\n"
,threshhold);
PRINT
"\nUseful commands in other menus: \n");
PRINT
" COORDS: changes X and Y coordinates; printer plots only the X coord.,y[%d]\n"
,X_coord);
PRINT
" PH: the number of times the Printer Head strikes each dot; now = %d\n"
,onprint);
PRINT
" XS: X Scale: X_left = %lf; X_right= %lf MUST be set\n"
,X_Lo[ScrnSec], X_Up[ScrnSec]);
PRINT
"\n YS: Y Scale: Y_lower = %lf Y_upper = %lf -- NOT needed for 'BIF'\n\n"
,Y_Lo[ScrnSec], Y_Up[ScrnSec]);
}
bif2 () { /* to execute command BIF2 */
if(SCREEN) {
printf(
"%ld preiterates followed by %ld iterates for each value of rho\n"
,bifPreIterates, bifIterates);
printf(" An example of input(both on one line):\n");
printf(" 200 700 <return> (no comma) \n");
printf(
" that is, 200 preiterates before plotting plus 700 iterates for each rho\n");
printf("ENTER 2 INTEGER VALUES \n");
}
#ifdef X11
if((input == StInput && sscanf(xwfgets(), "%ld %ld",
&bifPreIterates, &bifIterates) == 2 || input != StInput &&
fscanf(input, "%ld %ld", &bifPreIterates, &bifIterates) == 2)
#else
if(abortEnter() == NO &&
fscanf(input, "%ld %ld", &bifPreIterates, &bifIterates) == 2
#endif
&& SCREEN) {
printf("%ld preiterates followed by %ld iterates for each value of rho\n",
bifPreIterates, bifIterates);
}
}